import { Controller, Get, Post, Body, Patch, Param, Delete, Request, Query } from '@nestjs/common';
import { PurchaseService } from './purchase.service';
import { CreatePurchaseDto } from './dto/create-purchase.dto';

@Controller('purchase')
export class PurchaseController {
  constructor(private readonly purchaseService: PurchaseService) {}

  @Post('save')
  async create(@Body() createPurchaseDto: CreatePurchaseDto, @Request() req: any) {
      const result = await this.purchaseService.create(createPurchaseDto, req.tokenInfo );
      return { 
        message: result ? '操作成功': '失败'
      }
    }

  @Get('orders')
  async findAll(@Query() query: any) {
    const [data, total]:any = await this.purchaseService.findAll(query);
    return {
      data,
      total
    }
  }

  @Get('delete/:id')
  async delete(@Param('id') id: string) {
    const result = await this.purchaseService.delete(id);
    return { 
      message: result ? '完全删除成功': '失败'
    }
  }
  @Get('remove/:id')
  async remove(@Param('id') id: string) {
    const result = await this.purchaseService.remove(id);
    return { 
      message: result ? '删除成功': '失败'
    }
  }
}
